import getItemsFromCollect from '@/utils/getItemsFromCollect'
import useFinalPath from '@/hooks/useFinalPath'
import MarkdownContent from './useMarkdownContent'

const relativeItemMap = new Map<string, any>()

// const pathReg = /\\|\//

MarkdownContent.forEach((item, key) => {
  const basePath = useFinalPath(key).split("/")
  getItemsFromCollect(item, basePath.join("\\")).forEach((data) => {
    relativeItemMap.set(data.id, data)
  })
})

/**
 * 获取物品集合的物品属性，用于跳转物品集合内的物品
 * @param id 来自物品集合的物品 id
 */
export default function useItemCollectPath(id: string): { id: string; name: string; path: string } {
  id = id.replace("providencraft:", "")
  return relativeItemMap.get(id)
}